<template>
<view>
	<view class="d-kuan">
		<view class="d-waikuang-10">
			<view class="d-beijing-bai d-neikuang-10 d-yuanjiao-10 d-xia-10">
				<u-cell
					size="large"
					title="账户绑定小程序"
					value=""
					:isLink="false"
				>
				<u-icon slot="icon" size="20" name="weixin-fill"></u-icon>
				</u-cell>
				<view v-if="yonghuXinxi.openids" class="d-kuan d-yuanjiao-10">
					
					<view  class="d-xia-10">
						<u-button type="info" :plain="true" @click="" class="d-xia-10">已绑定小程序账号</u-button>
					</view>
					<view  class="d-xia-10">
						<u-button type="info" :plain="true" @click="jiebang" class="d-xia-10">解绑小程序</u-button>
					</view>
				</view>
				<view v-else class="d-kuan d-yuanjiao-10">
				
					<view class="d-xia-10">
						<u-button type="info" :plain="true" @click="bangdingYicun" class="d-xia-10">未绑定小程序账号</u-button>
					</view>
					
				</view>
			</view>
			
			<view class="d-beijing-bai d-neikuang-10 d-yuanjiao-10 d-xia-10">
				<u-cell
					size="large"
					title="小程序绑定账户"
					value=""
					:isLink="false"
				>
				<u-icon slot="icon" size="20" name="plus-people-fill"></u-icon>
				</u-cell>
				<form >
					<view class="d-kuan d-yuanjiao-10 d-xia-10">
						<u--input
							placeholder="请输入用户名"
							border="surround"
							clearable
							v-model="username" 
							id="username"
						  ></u--input>
					</view>
					<view class="d-kuan d-yuanjiao-10 d-xia-10">
						<u--input
							placeholder="请输入密码"
							border="surround"
							clearable
							v-model="password" 
							id="password"
						  ></u--input>
					</view>
					<view class="d-kuan d-yuanjiao-10">
					
						<view class="d-xia-10">
							<u-button type="info" :plain="true" @click="d_bangdingzhanghao" class="d-xia-10">确认绑定账号</u-button>
						</view>
						
					</view>
				</form>
			</view>
			
			<view class="d-kuan d-yuanjiao-10">
			
				<view class="d-xia-10">
					<u-button type="info" :plain="true" @click="shuaxinshuju" class="d-xia-10">刷 新</u-button>
				</view>
				
			</view>
		</view>
	</view>
	
	
</view>
</template>

<script>

var Api = require("../../utils/api.js");
var util = require("../../utils/util.js");

var wxApi = require("../../utils/wxApi.js");
var wxRequest = require("../../utils/wxRequest.js");
import config from "../../utils/config";
var pageCount = config.getPageCount;
var webSiteName = config.getWebsiteName;
var domain = config.getDomain;
const app = getApp();
/*#ifdef APP-PLUS || H5*/
    var member = uni.getStorageSync('member');
/*#endif*/
/*#ifdef MP-WEIXIN*/
    var member = uni.getStorageSync('member');
/*#endif*/

export default {
  data() {
    return {
      isArticlesList: true,
      listStyle: config.getListStyle,
      shareTitle: config.getWebsiteName,
      pageTitle: '小程序账号管理',
      articlesList: [],
	  yonghuXinxi: [],
      postype: "post",
      webSiteName: webSiteName,
      domain: domain,
	  member: '',
	  show: false,
	  username: '',
	  password: '',
    };
  },
  computed: {
  	
  },
  watch: {
      yonghuXinxi(newVal, oldVal) {
        // 当message属性发生变化时，执行刷新操作
        //uni.reLaunch({ url: '/pages/wo/bangdingyicun' });
      }
    },
  components: {},
  props: {},
  onShow: function () {
	  
  },
  onPullDownRefresh: function () {
    this.getYonghuXinxi();
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
 
    this.getYonghuXinxi();
	
	console.log(member);
	//判断用户是否登录
	var userInfo = uni.getStorageSync('userInfo');
	if (userInfo) {
		// 保留二次开发
	} else {
		//否则跳转到登录页面
		uni.reLaunch({ url: '/pages/login/login'}) // 跳转到首页
	}
	
    var postype = 'post';

    if (options.postype) {
      postype = options.postype;
    }

    this.setData({
      postype: postype
    });
  },
  onReady: function () {
    uni.setNavigationBarTitle({
      title: this.pageTitle
    });
  },
  
  methods: {

		formSubmit: function (e) {
		  var url = '../list/list';
		  var key = '';

		  if (e.currentTarget.id == "search-input") {
			key = e.detail.value;
		  } else {
			key = e.detail.value.input;
		  }

		  if (key != '') {
			url = url + '?search=' + key;
			uni.navigateTo({
			  url: url
			});
		  } else {
			uni.showModal({
			  title: '提示',
			  content: '请输入内容',
			  showCancel: false
			});
		  }
		},
		bangdingYicun(){
			uni.navigateTo({
			    url: '/pages/wo/bangdingyicun',
			});
		},
		jiebang() {
			uni.navigateTo({
			    url: '/pages/wo/jiebang',
			});
		},
		//会员信息
		getYonghuXinxi() {
			var self = this; 
		
			var getYonghuXinxiRequest = wxRequest.getRequest(Api.getYonghuXinxi(member.id));
			getYonghuXinxiRequest.then(response => {
				if (response.data.code == 1) {
				  //console.log(response.data.data); 
				  self.yonghuXinxi = response.data.data
				} else {
				  self.setData({
					displaySwiper: "none"
				  });
				}
			});
		},
		shuaxinshuju() {
		  // 刷新页面并重新获取数据
		  uni.reLaunch();
		  this.yonghuXinxi = this.getYonghuXinxi();
		},
		//账户绑定小程序
		d_bangdingzhanghao() {
			var self = this; 
			self.setData({
			    bangdingdata: []
			});
			var name = this.username;
			var password = this.password;
			var datas = "is_ajax=1&data[username]="+name+"&data[password]="+password+"&oid="+member.uid;
			var postWeixinBangdingRequest = wxRequest.postRequest(Api.postWeixinBangding(),datas);
				postWeixinBangdingRequest.then(response => {
					if (response.data.code == 1) {
						console.log(response.data.msg);
						uni.showToast({
							title: response.data.msg,
							icon: 'success',
							success: function () {
							}
						});
					} else {
						uni.showToast({
							title: response.data.msg,
							icon: 'error',
						});
					}
				});
		}
	}
    
};
</script>
<style>
@import "./wo.css";
page {
	background-color: #f3f4f7;
}
</style>